<!-- 搜索项目 -->
<template>
  <h-select-input-popup
    ref="hSelectInputPopup"
    v-model="val"
    v-bind="$attrs"
    v-on="$listeners"
    :params="queryParams"
    :keywords.sync="keywords"
    :getList="getList"
    :records="false"
    :use-search="false"
    @getDetail="getDetail"
		:isMulti="muitFlag"
    @change="$emit('change', $event)"
  >
    <template v-slot:default="{ item }">
      <view class="project-item">
        <view class="option">
          <view class="lf">款项名称</view>
          <view class="rl">{{ item.nodeName }}</view>
        </view>
        <view class="option">
          <view class="lf">应收款金额</view>
          <view class="rl">{{ item.paymentMoney }}</view>
        </view>
        <view class="option">
          <view class="lf">预回款日期</view>
          <view class="rl">{{ item.preCollectionDate }}</view>
        </view>
        <view class="option">
          <view class="lf">款项节点说明</view>
          <view class="rl">{{ item.nodeDesc }}</view>
        </view>
      </view>
    </template>
  </h-select-input-popup>
</template>

<script>
import { queryListByContractId, erpProgressPaymentNodeQueryById, erpProgressPaymentNodeQueryByIds } from '@/api/index.js'

export default {
  name: 'HSelectFinanceInvoiceBillInputPopup',
  data() {
    return {
      getList: queryListByContractId,
      params: {
        column: 'createTime',
        order: 'desc',
        pageNo: 1,
        pageSize: 10,
      },
      keywords: '',
    }
  },
  model: {
    prop: 'value',
    event: 'input',
  },
  props: {
    value: {
      type: [String, Number, Array],
      default: null,
    },
    contractId: {
      required: true,
      default: '',
    },
    muitFlag: {
      type: Boolean,
      default: false,
    },
		// 是否是财务模块显示的名称
		isFinance: {
			type: Boolean,
			default: false
		}
  },
  computed: {
    val: {
      get() {
        return this.value
      },
      set() {
        this.$emit('input', this.value)
      },
    },
    queryParams() {
      const params = {
        ...this.params,
        contractId: this.contractId
      }
			// 是否是财务模块显示的名称
			if (this.isFinance) {
				params.isFinance = 1
			}
      if (this.keywords) {
        params.nodeName = '*' + this.keywords + '*'
      }
      if (this.orgCode) {
        params.sysOrgCode = this.orgCode
      }
      if (this.checkStatus) {
        params.checkStatus = this.checkStatus
      }
      return params
    },
  },
  methods: {
    // 获取详情
    getDetail(value) {
			if (this.muitFlag) {
			  erpProgressPaymentNodeQueryByIds({ ids: value }).then((res) => {
			    if (res.success) {
			      const contractName = res.result.map(i => i.nodeName).join(',')
			      this.$refs.hSelectInputPopup.title = contractName
			      this.$emit('select', {
			        data: res.result,
			        id: value,
			      })
			    }
			  })
			} else {
				erpProgressPaymentNodeQueryById({ id: value }).then((res) => {
				  if (res.success) {
				    this.$refs.hSelectInputPopup.title = res.result.nodeName
				    this.$emit('select', {
				      data: res.result,
				      id: value,
				    })
				  }
				})
			}
    },
  },
}
</script>

<style lang="scss" scoped>

// 按钮
.btn {
  position: fixed;
  bottom: 20rpx;
  width: 95%;
}
</style>
